import { Injectable } from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { InjectModel } from '@nestjs/sequelize';
import SysUser from './entities/sys.user.entity';
import { Status } from '@libs/common';
 

@Injectable()
export class UserService {

  @InjectModel(SysUser)
  private sysUser: typeof SysUser
  
  async create(createUserDto: CreateUserDto) {
    const result = await this.sysUser.create(createUserDto)
    console.log(result)
    return result;
  }

  async findAll() {
    return await this.sysUser.findAll();
  }

  findOne(id: number) {
    return `This action returns a #${id} user`;
  }

  async findByAccountAndPassword(account: string, password: string): Promise<SysUser> {
    return await this.sysUser.findOne({ 
      where: { 
        account,
        password,
        // 表示启用
        status: Status.ENABLE
      } 
    });
  }

  update(id: number, updateUserDto: UpdateUserDto) {
    return `This action updates a #${id} user`;
  }

  remove(id: number) {
    return `This action removes a #${id} user`;
  }
}
